<template>
  <!-- 这是家具的主页 -->
  <div id="furniture">
    <el-container>
      <el-header><Header></Header></el-header>
      <el-main>
        <div class="content_bottom">
          <!-- 家具类别 -->
          <div class="top_text">
            <h1>
              <span>{{ $t("category.APPLIANCE.title") }}</span>
            </h1>
          </div>

          <div class="bottom_category">
            <div class="category_ul">
              <el-tabs v-model="activeName" @tab-click="handleClick" type="card">
                <el-tab-pane class="tuijian" label="全部" name="1372"></el-tab-pane>
                <el-tab-pane v-for="bmitem in info" :label="bmitem.category_name" :name="bmitem.category_id+''" :key="bmitem.category_id">
                  <ul>
                    <li v-for="datas in bmitem.child" :key="datas.category_id" :class="{ active: active == datas.category_id }" @click="select(datas.category_id)">
                      {{ datas.category_name }}
                    </li>
                  </ul>
                </el-tab-pane>
              </el-tabs>
            </div>
            <div class="order_null" v-if="BMlist.length <= 0">
              <img src="../../assets/404.png" alt="" />
            </div>
            <div class="category_obj" v-else>
              <ul class="bottom_ul">
                <li
                  v-for="(item, index) in BMlist"
                  :key="index"
                  @click="details(item.goods_id)"
                >
                  <img :src="url + item.goods_image" alt="" />
                  <p>{{ item.title }}</p>
                  <span>{{ item.min_price }} 元</span>
                </li>
              </ul>
            </div>
            <!-- 分页 -->
            <div class="pagination" v-show="pagBool">
              <el-pagination
                background
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-size="pageSize"
                layout="total, prev, pager, next, jumper"
                :total="totals"
              >
              </el-pagination>
            </div>
          </div>
        </div>
        <div id="furniture_content">
          <div class="content_top">
            <div class="top_parentBox">
              <router-link :to="{ path: './store', query: { Id: 164 } }">
                <video
                  class="index_video_hight"
                  src="../../../public/mp4/0611(18).mp4"
                  loop="loop"
                  muted
                  autoplay="autoplay"
                ></video>
              </router-link>
            </div>
          </div>
        </div>
      </el-main>
      <el-footer><Footer></Footer></el-footer>
    </el-container>
  </div>
</template>

<script>
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
export default {
  data() {
    return {
      currentPage: 1, //默认第一页
      pageSize: 9, //每页显示多少条数据
      totals: 0, //一共多少条数据
      pagBool: false, //分页的显示隐藏
      fenleiID: "", //分类id,请求分页使用
      allID: "1304", //家具id
      BMlist: [], //推荐
      info: [], //家具分类
      url: "https://mp.uekea.cn/attachment/",
      activeName: "1372",
      active: "",
    };
  },
  components: {
    Header,
    Footer,
  },
  methods: {
    // 选项卡点击
    handleClick(tab, event) {
      console.log(tab.name);
      console.log(event);
      var _this = this;
      var soID = tab.name;
      _this.fenleiID = _this.allID;
      _this.$get(`goods/list/category/${soID}`).then((res) => {
        if (res.code == 200) {
          _this.BMlist = res.data.goodsList;
          _this.allID = res.data.category_id;
          if (res.data.page[0].total > 9) {
            _this.totals = res.data.page[0].total;
            _this.pagBool = true;
          } else {
            _this.pagBool = false;
          }
        } else {
          _this.BMlist = [];
        }
      });
    },
    // 跳到商品列表
    more() {
      this.$router.push({ path: "./goods" });
    },
    // 跳到详情页面
    details(id) {
      this.$router.push({ path: "./goodsDetail", query: { id: id } });
    },
    // 选择分类，请求商品
    select(id) {
      var _this = this;

      _this.fenleiID = id;
      this.active = id;
      // 商品请求数据
      _this.$get(`goods/list/category/${id}`).then((res) => {
        if (res.code == 200) {
          // res.data.
          _this.BMlist = res.data.goodsList;
          if (res.data.page[0].total > 9) {
            _this.totals = res.data.page[0].total;
            _this.pagBool = true;
          } else {
            _this.pagBool = false;
          }
        } else {
          _this.BMlist = [];
        }
      });
    },
    // 分页监听当前所在页数
    handleCurrentChange(val) {
      var _this = this;
      _this.$get(`goods/list/category/${_this.fenleiID}/${val}`).then((res) => {
        if (res.code == 200) {
          _this.BMlist = res.data.goodsList;
        } else {
          _this.BMlist = [];
        }
      });
    },
  },
  created() {
    var _this = this;
    // _this.allID = _this.$route.query.Id;
    // 家具类别，请求数据
    _this.$get(`goods/category/${_this.allID}`).then((res) => {
      if (res.code == 200) {
        _this.info = res.data;
      } else {
        _this.info = [];
      }
    });
    _this.fenleiID = _this.allID;
    // 推荐全部数据
    _this.$get(`goods/list/category/${_this.allID}`).then((res) => {
      if (res.code == 200) {
        _this.BMlist = res.data.goodsList;
        console.log(res.data.goodsList);
        if (res.data.page[0].total > 9) {
          _this.totals = res.data.page[0].total;
          _this.pagBool = true;
        } else {
          _this.pagBool = false;
        }
      } else {
        _this.BMlist = [];
      }
    });
  },
};
</script>

<style lang="less" scoped>
// 布局容器
.el-header {
  background-color: white !important;
  font-size: 0;
}
.el-header,
.el-footer {
  color: #333;
  text-align: center;
  height: auto !important;
  padding: 0px;
}
.el-main {
  color: #333;
  padding: 0px;
  // 计算减去头部和底部的高度，就是中间的高度
  min-height: calc(100vh - 61px - 220px);
}
.el-aside {
  color: #333;
  text-align: center;
}
// 布局容器结束
.order_null{
  height: 400px;
  text-align: center;
  img{
    height: 400px;
  }
}
#furniture {
  min-width: 1140px;
}
.active {
  background: #409eff;
  border: 1px solid #409eff;
  color: #fff !important;
}
/deep/.el-tabs__item {
  padding: 0 20px;
  height: 40px;
  box-sizing: border-box;
  line-height: 40px;
  display: inline-block;
  list-style: none;
  font-size: 16px !important;
  font-weight: 500;
  color: #606266;
  position: relative;
}
.el-tab-pane ul li {
  display: inline-block;
  height: 30px;
  line-height: 30px;
  margin-right: 15px;
  cursor: pointer;
  font-size: 16px;
  color: #606266;
}

.top_text {
  margin: 60px 0px;
  h1 {
    width: 1200px;
    margin: auto;
    text-indent: 3em;
    span {
      font-size: 42px;
      padding-bottom: 5px;
      border-bottom: 2px solid black;
      color: black;
      letter-spacing: 5px;
    }
  }
}
.content_top {
  margin-bottom: 140px;
  .top_parentBox {
    margin: auto;
    width: 1200px;
    height: 550px;
    video {
      width: 100%;
      height: 100%;
    }
  }
}
.content_bottom {
  width: 65%;
  min-width: 1140px;
  margin: auto;
  h3 {
    margin-top: 90px;
    font-size: 30px;
    .border {
      display: inline-block;
      width: 30px;
      border-bottom: 3px solid #e2b972;
      margin-left: 17px;
    }
  }
  .bottom_category {
    background-color: white;
    margin-top: 50px;
    padding: 20px;
  }
  .bottom_ul {
    width: 100%;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    text-align: center;
    margin-bottom: 50px;
    li {
      // border-radius: 10px;
      width: 26%;
      margin-top: 50px;
      margin-bottom: 10px;
      transition-duration: 1s;
      overflow: hidden;
      img {
        // border-radius: 10px;
        height: 297px;
        width: 100%;
      }
      p {
        padding: 0px;
        height: 60px;
        line-height: 50px;
        padding-top: 10px;
        padding-left: 15px;
        padding-right: 15px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin: 0px;
        font-size: 17px;
      }
      span {
        color: #e2b972;
        display: inline-block;
        margin-bottom: 20px;
        font-size: 16px;
      }
    }
    li:hover {
      transform: translateY(-10px);
      transition-duration: 1.5s;
      box-shadow: 0px 8px 12px 3px #4e5454;
    }
  }
  .bottom_ul::after {
    content: "";
    display: block;
    width: 26%;
  }
  .more {
    display: block;
    width: 100px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    margin: 0 auto;
    border: 1px solid #000;
  }
  .more:hover {
    color: #fff;
    background-color: #000;
  }
}
// 推荐
.tuijian {
  cursor: pointer;
  font-size: 16px;
}
// 类别
.category_title {
  font-size: 25px;
  font-weight: 700;
  margin: 0px;
  margin-bottom: 10px;
  padding: 20px 0px;
  border-bottom: 2px solid #ccc;
  text-indent: 1em;
}
.category_flex {
  display: flex;
  flex-wrap: wrap;
  text-align: center;
  justify-content: space-between;
  .category_content {
    width: 25%;
    padding: 25px;
    .category_imgs {
      width: 130px;
      height: 130px;
      margin: auto;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .category_text {
      font-size: 17px;
      padding: 15px 0px;
    }
  }
}
.category_flex::after {
  content: "";
  display: block;
  flex: 1;
}
.dropdown_text {
  font-size: 16px !important;
}
// 类别
.category_ul {
  border-bottom: 2px solid #ccc;
  height: auto;
  line-height: 48px;
  display: flex;
  justify-content: left;
  li {
    display: inline-block;
    text-align: center;
    min-width: 80px;
    color: #606266;
    span {
      font-size: 16px;
    }
  }
}
.pagination {
  width: 100%;
  margin-top: 35px;
  margin-bottom: 45px;
  text-align: center;
}
/deep/ .el-pagination span:not([class*="suffix"]) {
  font-size: 15px;
}
/deep/ .el-pagination button {
  height: 30px;
}
/deep/ .el-pagination.is-background .btn-prev {
  min-width: 32px;
}
/deep/ .el-pager li {
  height: 30px;
  line-height: 30px;
  font-size: 15px;
}
/deep/ .el-pagination.is-background .el-pager li {
  min-width: 32px;
}
/deep/ .el-pagination .btn-prev .el-icon {
  font-size: 18px;
}
/deep/ .el-pagination .btn-next .el-icon {
  font-size: 18px;
}
</style>